package com.cmcc.groupcontacts.util;

import java.lang.reflect.Field;

import android.content.Context;
import android.content.DialogInterface;

import com.cmcc.groupcontacts.MainApp;

/**
 * 
 * 对话框工具类
 * 
 * @author 
 * 
 */
public abstract class DialogUtil {
	private static final String LOG_TAG = "DialogUtil";

	/**
	 * 是否在点击按钮时自动关闭对话框
	 * 
	 * @param dialog
	 * @param bx
	 */
	public static void closeDialog(DialogInterface dialog, Boolean bx) {
		closeDialog(MainApp.instance, dialog, bx);
	}

	/**
	 * 是否在点击按钮时自动关闭对话框
	 * 
	 * @param context
	 * @param dialog
	 * @param bx
	 */
	public static void closeDialog(Context context, DialogInterface dialog, Boolean bx) {
		try {
			// mShowing=false时表示对话框已关闭，因而中断了关闭对话框的操作
			Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
			field.setAccessible(true);
			field.set(dialog, bx);
			dialog.dismiss();
		} catch (Exception e) {
			ExceptionHandler.handleAcceptable(e, "设置对话框是否允许关闭时出错");
		}
	}
}
